package com.rceeslca.modules.cam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rceeslca.common.utils.Result;
import com.rceeslca.modules.cam.entity.CamMajor;
import com.rceeslca.modules.cam.param.PageQueryParam;
import com.rceeslca.modules.cam.service.CamUserService;
import com.rceeslca.modules.cam.vo.CamUserVo;
import com.rceeslca.modules.sys.dto.SysDeptDTO;
import com.rceeslca.modules.sys.dto.SysUserDTO;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户
 */
@Api(tags="用户")
@AllArgsConstructor
@RestController
@RequestMapping("/cam/user")
public class CamUserController {

    @Autowired
    private CamUserService camUserService;


    /**
     * 分页查询学生数据
     * @param param 条件参数
     */
    @PostMapping("pageStudent")
    public Result<IPage<CamUserVo>> pageStudent(@RequestBody PageQueryParam<CamUserVo> param) {

        param.getQuery().setRoleName("学生");
        Page<CamUserVo> page = new Page<>(param.getPageNum(),param.getPageSize());
        IPage<CamUserVo> iPage = camUserService.pageList(page,param.getQuery());

        return new Result<IPage<CamUserVo>>().ok(iPage);
    }


    /**
     * 分页查询教师数据
     * @param param 条件参数
     */
    @PostMapping("pageTeacher")
    public Result<IPage<CamUserVo>> pageTeacher(@RequestBody PageQueryParam<CamUserVo> param) {

        param.getQuery().setRoleName("教师");
        Page<CamUserVo> page = new Page<>(param.getPageNum(),param.getPageSize());
        IPage<CamUserVo> iPage = camUserService.pageList(page,param.getQuery());

        return new Result<IPage<CamUserVo>>().ok(iPage);
    }


    /**
     * 列展示
     * @param param 条件参数
     */
    @PostMapping("getList")
    public Result<List<CamUserVo>> getList(@RequestBody CamUserVo param) {

        List<CamUserVo> dataList = camUserService.listUser(param);

        return new Result<List<CamUserVo>>().ok(dataList);
    }


    /**
     * 创建
     * @param major 专业
     */
    @PostMapping("batchAdd")
    public Result batchAdd(@RequestBody List<SysUserDTO> userDtoList) {

        camUserService.batchAdd(userDtoList);

        return new Result();
    }

}
